
#ifndef UPDATE_CAROUSEL_IMAGE_WINDOW_H
#define UPDATE_CAROUSEL_IMAGE_WINDOW_H

#include <QWidget>
#include <QScrollArea>
#include <QTimer>
#include <QPropertyAnimation>
#include <QPushButton>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QEvent>

class CarouselImageWindow : public QWidget
{
Q_OBJECT
public:
    CarouselImageWindow(QWidget *parent = nullptr);
    ~CarouselImageWindow();

    // 设置图片列表;
    void setImageList(QStringList imageFileNameList);
    // 添加图片;
    void addImage(QString imageFileName);
    // 开始播放;
    void startPlay();

    void getFileName();

private:
    // 初始化图片切换按钮;
    void initChangeImageButton();
    // 绘图事件;
    void paintEvent(QPaintEvent *event);

    // 鼠标点击事件;
    void mousePressEvent(QMouseEvent* event);

    bool eventFilter(QObject* obj, QEvent* event);

public slots:
    // 图片切换时钟;
    void onImageChangeTimeout();

    // 图片切换按钮点击;
    void onImageSwitchButtonClicked(int buttonId);
    void dealAdvertisementBack(const QJsonObject &obj);

    void replyFinished(QNetworkReply *reply);

private:
    // 用来做图片切换滑动效果，目前以透明度作为切换效果;
    QScrollArea* image_play_widget_;
    // 图片列表;
    QList<QString> image_file_name_list_;

    // 图片切换时钟;
    QTimer image_change_timer_;

    // 当前显示图片index;
    int current_index_;

    // 切换图片;
    QPixmap current_pixmap_;
    QPixmap next_pixmap_;
    // 图片切换动画类;
    QPropertyAnimation* opacity_animation_;
    // 按钮列表;
    QList<QPushButton*> button_list_;

    QNetworkAccessManager *network_manager_{nullptr};

    QStringList names_{};
    QStringList pic_names_{};

    QStringList url_list_{};
    QStringList image_list_{};
};
#endif //UPDATE_CAROUSEL_IMAGE_WINDOW_H
